home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / DETH_SRC.ZIP / DETHROID.C next >
C/C++ Source or Header  |  1995-05-08  |  61KB  |  2,529 lines

  1. /* DeathRoids Source!
  2.  *
  3.  *    I hope you aren't expecting too many comments, because there are
  4.  * practically none.  If you have trouble figuring anything out,
  5.  *    drop me a message.
  6.  *
  7.  *    All of the file loading routines have right over them the
  8.  *    original file names, so just switch the comments to use those.
  9.  *
  10.  *********************************************************
  11.  *    NOTICE:  PERMISION TO USE AND/OR MODIFY THIS SOURCE
  12.  * CODE IS HEREBY GRANTED BY THE AUTHOR PROVIDED THAT
  13.  *    NO FEE IS CHARGED FOR THIS PRODUCT OR ANY PRODUCT THAT
  14.  *    USES DIRECT SOURCE FROM THIS PRODUCT. NEITHER ARE
  15.  * ANY OR ALL OF THE GRAPHICS IMAGES TO BE USED IN
  16.  * COMMERCIAL PRODUCTS WITHOUT THE EXPRESS CONSENT OF
  17.  *    THE AUTHOR.
  18.  *
  19.  *      (Basically, this is free, so keep it that way :)
  20.  *********************************************************
  21.  *
  22.  *    Note: Written in BC++ 3.1, so I use both "//" and "/*" for
  23.  *            commenting.  Also, Tab size is 3.
  24.  *            The project file consists of "asteroid.c", "sound.c",
  25.  *            "dmalib.c" and "timerx.c"  These other files are part
  26.  *            of the SOUNDX sound system, which can be found on
  27.  *            "x2ftp.oulu.fi" in the "/pub/msdos/programming/music"
  28.  *       directory.
  29.  *
  30.  * TAB SIZE: 3
  31.  *
  32. */
  33.  
  34. #include <stdlib.h>
  35. #include <stdio.h>
  36. #include <conio.h>
  37. #include <stdio.h>
  38. #include <math.h>
  39. #include <bios.h>
  40. #include <time.h>
  41. #include <stddef.h>
  42. #include <dos.h>
  43. #include <io.h>
  44. #include <fcntl.h>
  45. #include <alloc.h>
  46. #include <malloc.h>
  47. #include <sys\stat.h>
  48. #include "mydef.h"
  49. #include "sound.h"
  50. #include "timerx.h"
  51. #include "dmalib.h"
  52.  
  53. extern volatile BYTE voc_mode;
  54.  
  55. char huge *loadsound(char *filename);
  56.  
  57. unsigned char pal[768];
  58.  
  59. #define TSENG         '1'
  60. #define TRIDENT     '2'
  61. #define ATI            '3'
  62. #define VESA        '4'
  63. char graphics_chip;
  64. int ati_index;
  65. unsigned char ReadWin, WriteWin;
  66.  
  67. // speed delay for faster computers
  68. int buldelay, rockdelay;
  69.  
  70. // for accessing the registers for using interrupts
  71. union REGS regs;
  72. struct SREGS sregs;
  73.  
  74. // for detecting key-presses
  75. #define PRESSED    1
  76. #define UNPRESSED    0
  77.  
  78. #define MAXBUL     20            // max number of bullets on screen
  79. #define MAXROCK    20            // max number of rocks on screen
  80. //#define MAXSPEED    6
  81. #define MAXSPEED    6291456
  82. //#define MAXSPEED    10291456
  83.  
  84. #define ROCK_DELAY_RATE 2
  85.  
  86. // total number of pictures for each type of object
  87. #define NUM_SHIP_PICS    40
  88. #define NUM_ROCK_PICS    22
  89. #define NUM_BUL_PICS        25
  90.  
  91. //#define NUM_ROCK_PICS    5
  92.  
  93. // Maximum / minimum screen coordinates for objects
  94. //#define MAX_WIN_X    960
  95. #define MAX_WIN_X    990
  96. #define MIN_WIN_X 35
  97. #define MAX_WIN_Y 715
  98. #define MIN_WIN_Y 35
  99.  
  100. // number of stars in the background
  101. #define NUMSTARS    150
  102.  
  103. // So I don't have to use floats, I shift (multiply) integers.
  104. #define FSCALE        1048576    // Float -> Integer scale
  105. #define FSHIFT        20            // 2^20 = 1048576
  106.  
  107. // number of degrees the player turns each time they press left or right
  108. #define TURNRATE    3
  109.  
  110. // These are macros for speed, so I don't have to call another
  111. // function.  Note that graphics_chip is always VESA, but since
  112. // that wouldn't slow this down *too* much, I didn't bother to
  113. // change it.
  114. #define putpixel(x,y,col) *((char far *)0xA0000000+x+(y<<10))=col
  115. #define SetWriteBank(bank)                                  \
  116.     if (graphics_chip == TSENG)                             \
  117.         outportb(0x3CD,bank);                                 \
  118.     else if (graphics_chip == TRIDENT)                     \
  119.         outport(0x3C4,((bank^2)<<8)+0x0E);                 \
  120.     else if (graphics_chip == ATI)                         \
  121.     {                                                                 \
  122.         outportb(ati_index,0xB2);                             \
  123.         outportb(ati_index+1,bank<<1);                    \
  124.     }                                               \
  125.     else if (graphics_chip == VESA)                 \
  126.     {                                               \
  127.         regs.x.ax = 0x4F05;                          \
  128.         regs.h.bh = 0x00;                            \
  129.         regs.h.bl = WriteWin;                        \
  130.         regs.x.dx = bank;                            \
  131.         int86(0x10,®s,®s);                     \
  132.     }
  133. #define SetReadBank(bank)                                    \
  134.     if (graphics_chip == TSENG)                             \
  135.         outportb(0x3CD,(bank)<<4);                         \
  136.     else if (graphics_chip == TRIDENT)                     \
  137.         outport(0x3C4,(bank<<8)+0x0E);                     \
  138.     else if (graphics_chip == ATI)                         \
  139.     {                                                                 \
  140.         outportb(ati_index,0xB2);                             \
  141.         outportb(ati_index+1,bank<<5);               \
  142.     }                                               \
  143.     else if (graphics_chip == VESA)                 \
  144.     {                                               \
  145.         regs.x.ax = 0x4F05;                          \
  146.         regs.h.bh = 0x00;                            \
  147.         regs.h.bl = ReadWin;                                    \
  148.         regs.x.dx = bank;                            \
  149.         int86(0x10,®s,®s);                     \
  150.     }
  151.  
  152. //        outportb(ati_index+1,(inportb(ati_index+1)&0xE1)|(bank << 1)); \
  153. //        outportb(ati_index+1,(inportb(ati_index+1)&0xE1)|(bank << 1)); \
  154.  
  155. #define SHIP_SIZE        52
  156. #define ROCK_LG_SIZE 52
  157. #define ROCK_MD_SIZE 40
  158. #define ROCK_SM_SIZE 28
  159. #define BUL_SIZE        16
  160.  
  161. struct star_type
  162. {
  163.     int x,y;
  164.     char col;
  165. } star[NUMSTARS];
  166.  
  167. // Very convenient types: boolean flags, status flags, and rock sizes
  168. typedef enum { off     =  0, on         = 1                         } flag;
  169. //typedef enum { dieing = -1, inactive = 0, active = 1         } statflag;
  170. #define dieing -1
  171. #define inactive 0
  172. #define active 1
  173. typedef enum { small     =  1, med         = 2, large     = 3     } sizetype;
  174.  
  175. //double dsint[360];                //    degrees sin() table: FAST!!
  176. //double dcost[360];                // degrees cos() table: FAST!!
  177. long int dsint[360];
  178. long int dcost[360];
  179.  
  180. int level;
  181.  
  182. struct bultype                    // Standard bullet type
  183. {
  184. //    float x,y;
  185.     int x,y;
  186. //    float dx,dy;                // (x,y) coords, (dx,dy) movement
  187.     long int dx, dy;
  188.     int lcount;                    // lifespan counter
  189.     short int curframe;        // current animation frame number
  190. //    statflag status;            // Active / Inactive flag
  191.     short int status;
  192. } bul[MAXBUL];                    // Global bull def.  May be moved to
  193.                                     // shiptype def. if multiple player!
  194.  
  195. struct player_shiptype        // Standard player-ship type
  196. {
  197. //    float x,y;
  198.     int x,y;
  199. //    float dx,dy;                // (x,y) coords, (dx,dy) movement
  200.     long int dx,dy;
  201.     int dir;                        // current direction (degrees)
  202.     int shield;                    // shield strength
  203.     long  int score;            // score
  204.     short int lives;            // number of lives
  205.     flag trishot,mgun,        // triple-shot, machine gun flags
  206.           luck,retros,            // luck, retro-rocket flags
  207.           autoshld,bomb,        // auto-shield, bomb flags
  208.           longshot;                // extra bul length flag
  209. //    statflag status;            // Active (alive) / Inactive / dieing. :)
  210.     short int status;
  211. } player;                        // global def - change to array if > 1 plyr.
  212.  
  213. struct rocktype                // Standard rock type
  214. {
  215. //    float x,y;
  216.     int x,y;
  217. //    float dx,dy;                // (x,y) coords, (dx,dy) movement
  218.     long int dx, dy;
  219.     short int curframe;        // current animation frame number
  220.     short int framedelay;
  221. //    statflag status;            // Active / Inactive / exploding flag
  222.     short int status;
  223.     sizetype size;                // size of rock
  224. } rock[MAXROCK];                // Global rock def.
  225.  
  226. void drawobject(signed char far object[],int x,int y);
  227. void drawshields(int shields);
  228.  
  229. // Homemade printf routine for graphics screens
  230. void Alpha(char s[], int x, int y);
  231. // for the Alpha() functions
  232. void PutLetter (int l, int x, int y);
  233.  
  234. // The definition of each character for the Alpha() function
  235. signed char aa[30] = {0,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
  236. signed char bb[30] = {1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,1,1,0,-3 };
  237. signed char cc[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
  238. signed char dd[30] = {1,1,1,1,0,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,0,-3 };
  239. signed char ee[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
  240. signed char ff[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-3 };
  241. signed char gg[30] = {1,1,1,1,1,-2,1,0,0,0,0,-2,1,0,0,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  242. signed char hh[30] = {1,0,0,1,1,-2,1,0,0,1,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
  243. signed char ii[30] = {1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-2,0,0,1,1,0,-2,1,1,1,1,1,-3 };
  244. signed char jj[30] = {1,1,1,1,1,-2,0,0,0,1,0,-2,0,0,0,1,0,-2,1,1,0,1,0,-2,1,1,1,1,0,-3 };
  245. signed char kk[30] = {1,0,0,0,1,-2,1,0,0,1,0,-2,1,1,1,0,0,-2,1,1,0,1,0,-2,1,1,0,0,1,-3 };
  246. signed char ll[30] = {1,0,0,0,0,-2,1,0,0,0,0,-2,1,1,0,0,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  247. signed char mm[30] = {1,0,0,0,1,-2,1,1,0,1,1,-2,1,1,1,1,1,-2,1,0,1,0,1,-2,1,0,1,0,1,-3 };
  248. signed char nn[30] = {1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-2,1,0,1,1,1,-2,1,0,0,1,1,-3 };
  249. signed char oo[30] = {0,1,1,1,0,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,0,1,1,1,0,-3 };
  250. signed char pp[30] = {1,1,1,1,0,-2,1,0,0,1,1,-2,1,1,1,1,0,-2,1,1,0,0,0,-2,1,1,0,0,0,-3 };
  251. signed char qq[30] = {0,1,1,1,0,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,1,0,-2,0,1,1,0,1,-3 };
  252. signed char rr[30] = {1,1,1,1,0,-2,1,0,0,0,1,-2,1,1,1,1,0,-2,1,1,0,0,1,-2,1,1,0,0,1,-3 };
  253. signed char ss[30] = {0,1,1,1,1,-2,1,0,0,0,0,-2,1,1,1,1,1,-2,0,0,0,0,1,-2,1,1,1,1,0,-3 };
  254. signed char tt[30] = {1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-2,0,1,1,0,0,-2,0,1,1,0,0,-3 };
  255. signed char uu[30] = {1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  256. signed char vv[30] = {1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,0,1,0,1,0,-2,0,0,1,0,0,-3 };
  257. signed char ww[30] = {1,0,0,0,1,-2,1,0,1,0,1,-2,1,0,1,0,1,-2,1,1,1,1,1,-2,0,1,1,1,0,-3 };
  258. signed char xx[30] = {1,0,0,0,1,-2,1,1,0,1,1,-2,0,0,1,0,0,-2,1,1,0,1,1,-2,1,0,0,0,1,-3 };
  259. signed char yy[30] = {0,1,0,1,0,-2,1,1,0,1,1,-2,1,1,1,1,1,-2,0,0,1,0,0,-2,0,0,1,0,0,-3 };
  260. signed char zz[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,0,0,1,0,0,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  261.  
  262. signed char n1[30] = {0,1,1,1,0,-2,1,1,1,1,0,-2,0,0,1,1,0,-2,0,0,1,1,0,-2,1,1,1,1,1,-3 };
  263. signed char n2[30] = {1,1,1,1,1,-2,0,0,0,1,1,-2,0,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,1,-3 };
  264. signed char n3[30] = {1,1,1,1,1,-2,0,0,0,0,1,-2,0,1,1,1,1,-2,0,0,0,1,1,-2,1,1,1,1,1,-3 };
  265. signed char n4[30] = {1,0,1,1,0,-2,1,0,1,1,0,-2,1,1,1,1,1,-2,0,0,1,1,0,-2,0,0,1,1,0,-3 };
  266. signed char n5[30] = {1,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,0,-2,0,0,0,1,1,-2,1,1,1,1,1,-3 };
  267. signed char n6[30] = {1,1,1,1,1,-2,1,1,0,0,0,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  268. signed char n7[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-3 };
  269. signed char n8[30] = {1,1,1,1,1,-2,1,0,0,0,1,-2,1,1,1,1,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  270. signed char n9[30] = {1,1,1,1,1,-2,1,0,0,1,1,-2,1,1,1,1,1,-2,0,0,0,1,1,-2,0,0,0,1,1,-3 };
  271. signed char n0[30] = {1,1,1,1,1,-2,1,0,0,0,1,-2,1,0,0,0,1,-2,1,1,0,0,1,-2,1,1,1,1,1,-3 };
  272.  
  273. signed char col[30]= {0,0,0,0,0,-2,0,0,1,0,0,-2,0,0,0,0,0,-2,0,0,1,0,0,-2,0,0,0,0,0,-3 };
  274. signed char spc[30]= {0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-2,0,0,0,0,0,-3 };
  275.  
  276. signed char exc[30]= {0,1,0,1,0,-2,
  277.                              0,1,0,1,0,-2,
  278.                              0,1,0,1,0,-2,
  279.                              0,0,0,0,0,-2,
  280.                              0,1,0,1,0,-3 };
  281. signed char prd[30]= {0,0,0,0,0,-2,
  282.                              0,0,0,0,0,-2,
  283.                              0,0,0,0,0,-2,
  284.                              0,0,1,1,0,-2,
  285.                              0,0,1,1,0,-3 };
  286. signed char dsh[30]= {0,0,0,0,0,-2,
  287.                              0,0,0,0,0,-2,
  288.                              0,1,1,1,0,-2,
  289.                              0,0,0,0,0,-2,
  290.                              0,0,0,0,0,-3 };
  291. signed char lpar[30]={0,0,0,1,0,-2,
  292.                              0,0,1,0,0,-2,
  293.                              0,0,1,0,0,-2,
  294.                              0,0,1,0,0,-2,
  295.                              0,0,0,1,0,-3 };
  296. signed char rpar[30]={0,1,0,0,0,-2,
  297.                              0,0,1,0,0,-2,
  298.                              0,0,1,0,0,-2,
  299.                              0,0,1,0,0,-2,
  300.                              0,1,0,0,0,-3 };
  301. signed char lbrk[30]={0,1,1,1,0,-2,
  302.                              0,1,0,0,0,-2,
  303.                              0,1,0,0,0,-2,
  304.                              0,1,0,0,0,-2,
  305.                              0,1,1,1,0,-3 };
  306. signed char rbrk[30]={0,1,1,1,0,-2,
  307.                              0,0,0,1,0,-2,
  308.                              0,0,0,1,0,-2,
  309.                              0,0,0,1,0,-2,
  310.                              0,1,1,1,0,-3 };
  311. signed char starc[30]={0,0,1,0,0,-2,
  312.                              0,1,1,1,0,-2,
  313.                              1,1,1,1,1,-2,
  314.                              0,1,1,1,0,-2,
  315.                              0,0,1,0,0,-3 };
  316. signed char coma[30]={0,0,0,0,0,-2,
  317.                              0,0,0,0,0,-2,
  318.                              0,0,1,0,0,-2,
  319.                              0,0,1,0,0,-2,
  320.                              0,1,0,0,0,-3 };
  321. signed char ques[30]={0,1,1,1,0,-2,
  322.                              1,0,0,0,1,-2,
  323.                              0,0,1,1,0,-2,
  324.                              0,0,0,0,0,-2,
  325.                              0,0,1,0,0,-3 };
  326. signed char hapy[30]={0,1,0,1,0,-2,
  327.                              0,0,0,0,0,-2,
  328.                              0,0,1,0,0,-2,
  329.                              1,0,0,0,1,-2,
  330.                              0,1,1,1,0,-3 };
  331. signed char quot[30]={0,1,0,1,0,-2,
  332.                              0,1,0,1,0,-2,
  333.                              0,0,0,0,0,-2,
  334.                              0,0,0,0,0,-2,
  335.                              0,0,0,0,0,-3 };
  336. signed char apos[30]={0,0,1,0,0,-2,
  337.                              0,0,1,0,0,-2,
  338.                              0,0,0,0,0,-2,
  339.                              0,0,0,0,0,-2,
  340.                              0,0,0,0,0,-3 };
  341. signed char ampr[30]={0,1,1,0,0,-2,
  342.                              1,0,0,1,0,-2,
  343.                              1,0,1,0,0,-2,
  344.                              1,0,0,0,1,-2,
  345.                              0,1,1,1,0,-3 };
  346.  
  347. // Here's all my graphics pointers
  348. void far *ship_noshld_pic[NUM_SHIP_PICS];
  349. void far *aster_pic[NUM_ROCK_PICS];
  350. void far *ship_shld_pic[NUM_SHIP_PICS];
  351.  
  352. void far *med_aster_pic[NUM_ROCK_PICS];
  353. void far *small_aster_pic[NUM_ROCK_PICS];
  354.  
  355. void far *bullet_pic[NUM_BUL_PICS];
  356.  
  357. void Init_Graphics(void);
  358. void Init_Sound(void);
  359. void MovePlayer(void);
  360. void CheckPlayer(void);
  361. void DrawPlayer(void);
  362. void ErasePlayer(void);
  363. void MoveRock(short int rocknum);
  364. void CheckRock(short int rocknum);
  365. void DrawRock(short int rocknum);
  366. void EraseRock(short int rocknum);
  367. void MoveBul(short int bulnum);
  368. void CheckBul(short int bulnum);
  369. void DrawBul(short int bulnum);
  370. void EraseBul(short int bulnum);
  371. void CalcNewLevel(void);
  372. void drawscreen(void);
  373. void NewRock(int x, int y, sizetype size);
  374. void KillRock(short int rocknum);
  375. void Init_Game(void);
  376. void DoKeys(void);
  377. void De_Init_Sound(void);
  378. void De_Init_Graphics(void);
  379.  
  380. void Setup_Key_Interrupt(void);
  381. void Enable_Key_Interrupt(void);
  382. void Disable_Key_Interrupt(void);
  383.  
  384. // Detects keypresses
  385. void interrupt lookkey();
  386.  
  387. void bar(int x1, int y1, int x2, int y2);
  388. void rect(int x1, int y1, int x2, int y2);
  389. void cleardevice(void);
  390.  
  391. void getimage(void far *pic_ptr,int x1,int y1, int size);
  392. void putimage(void far *pic_ptr,int x,int y, int size);
  393. void eraseimage(void far *pic_ptr, int x, int y, int size);
  394.  
  395. void putpixel2(int x, int y, long color);
  396.  
  397. char getpixel(int x, int y);
  398. long getpixel2(int x, int y);
  399.  
  400. void chkkey(void);
  401.  
  402. int display_raw(int x, int y, char *filename, int xsize, int ysize);
  403. void loadpics(void);
  404.  
  405. void DrawStar(void);
  406. void set_intro_pal(void);
  407. int DoMenu(void);
  408. void draw_menu(void);
  409. void instruct(void);
  410.  
  411. void DeathScreen(void);
  412. void NewLevel(void);
  413.  
  414. // just for compatibility with Borland's graphics lib and
  415. // usuability for those of us who are used to it.
  416. #define setfillstyle(a,b) cur_color = b;
  417. #define setcolor(col_num) cur_color = col_num;
  418.  
  419. // current color
  420. unsigned char cur_color;
  421. flag sound_mode = on;
  422.  
  423. // various sounds in the game
  424. #define BEGIN        0
  425. #define FIRE      1
  426. #define HITROCK   2
  427. #define DIE       3
  428. #define QUIT        4
  429. #define MAXSND        5
  430. // Here's the sounds pointer, named soundb because something else
  431. // was already named "sound"
  432. char huge *soundb[MAXSND];
  433.  
  434. struct KEY_INT                    // Key interrupt structure
  435. {
  436.     int right;                    // key to turn right pressed / unpressed
  437.  
  438.     int left;                    // key to turn left pressed / unpressed
  439.     int thrust;                    // key to thrust pressed / unpressed
  440.     int esc;                        // key to quit pressed / unpressed
  441.     int fire;                    // key to fire pressed / unpressed
  442.     int shield;                    // key to raise shields pressed / unpressed
  443.     int pause;                    // key to pause pressed / unpressed
  444. } k;                                // Global def.
  445.  
  446. struct Key_Selections        // user key selections - contains key codes...
  447. {
  448.     int left_press;
  449.     int left_unpress;
  450.     int right_press;
  451.     int right_unpress;
  452.     int thrust_press;
  453.     int thrust_unpress;
  454.     int fire_press;
  455.     int fire_unpress;
  456.     int shield_press;
  457.     int shield_unpress;
  458. } keyOpt;                        // Global def. - changed only in Options menu
  459. // Options menu never added
  460.  
  461. struct address {
  462.     char far *p;
  463. } temp;
  464.  
  465. struct address far *addr = (struct address far *) 36;
  466. struct address far *int9 = (struct address far *) 240;
  467.  
  468. void main()
  469. {
  470.     int Quit = 0,i,j,num,complete;
  471.     char out[100];
  472. /*
  473.     printf("\nPlease enter graphics card:\n 1. Tseng ET4000 (Works!)\n");
  474.     printf(" 2. Trident 8900 (doesn't work)\n");
  475.     printf(" 3. ATI Graphics Ultra Mega Super Plus Pro (doesn't work)\n");
  476.     printf(" 4. *NEW!* VESA graphics adaptor! :)\n");
  477.     printf("\nWell?  What'll it be? ");
  478.     graphics_chip = getche();
  479. */
  480. /*
  481.     I've disabled support for specific chip sets and rather decided to
  482.     support only VESA.
  483. */
  484.  
  485.     graphics_chip = VESA;
  486.     printf("\n\nDo you want sound? (Y/N) ");
  487.  
  488.     switch (getche())
  489.     {
  490.         case 'Y':
  491.         case 'y': sound_mode = on; break;
  492.         case 'N':
  493.         case 'n': sound_mode = off; break;
  494.     }
  495.  
  496.     printf("\n\nEnter BULLET delay factor? (0 = default) > ");
  497.     scanf("%d",&buldelay);
  498.     printf("\nEnter ROCK delay factor?   (0 = default) > ");
  499.     scanf("%d",&rockdelay);
  500.  
  501.     if (buldelay == 0)
  502.         buldelay = 128;
  503.     if (rockdelay == 0)
  504.         rockdelay = 1024;
  505.  
  506.     Init_Graphics();
  507.     Init_Sound();
  508.  
  509.     Setup_Key_Interrupt();
  510.  
  511.  
  512.     // main loop
  513.     while (Quit != 1)
  514.     {
  515.         // go to the menu -- when they come back, they are either
  516.         // playing or quitting.
  517.         Quit = DoMenu();
  518.  
  519.         if (Quit != 1)
  520.         {
  521.             Enable_Key_Interrupt();
  522.  
  523.             Init_Game();
  524.  
  525.             if (sound_mode == on)
  526.                 VocPlay((char far *)soundb[BEGIN]);
  527.  
  528.             k.esc = UNPRESSED;
  529.             k.fire = UNPRESSED;
  530.  
  531.             while (k.esc != PRESSED)
  532.             {
  533.                 complete = 0;
  534.                 while (!complete && k.esc != PRESSED)
  535.                 {
  536.                     for (i = 0; i < MAXBUL; i++)
  537.                     {
  538.                         if (bul[i].status == active)
  539.                             MoveBul(i);
  540.                         else
  541.                         {
  542.                             DrawStar();
  543.                             for (j = 0; j < (MAXROCK-i)*buldelay;j++);
  544.                         }
  545.                     }
  546.  
  547.                     complete = 1;
  548.                     for (i = 0; i < MAXROCK; i++)
  549.                     {
  550.                         if (rock[i].status == active)
  551.                         {
  552.                             MoveRock(i);
  553.                             complete = 0;
  554.                         }
  555.                         else
  556.                         {
  557.                             DrawStar();
  558.                             for (j = 0; j < (MAXROCK-i)*rockdelay;j++);
  559.                         }
  560.                     }
  561.  
  562.                     MovePlayer();
  563.  
  564.                     DoKeys();
  565.  
  566.                     drawscreen();
  567.  
  568.                     if (player.status == dieing)
  569.                     {
  570.                         if (player.lives == 0)
  571.                             k.esc = PRESSED;
  572.                         else
  573.                         {
  574.                             for (i = 0; i < MAXROCK; i++)
  575.                                 if (rock[i].status == active)
  576.                                 {
  577.                                     EraseRock(i);
  578.                                 }
  579.                             for (i = 0; i < MAXBUL; i++)
  580.                             {
  581.                                 EraseBul(i);
  582.                                 bul[i].status = inactive;
  583.                             }
  584.  
  585.                             ErasePlayer();
  586.  
  587.                             player.shield     = 200;
  588.                             player.lives  -= 1;
  589.                             player.trishot = off;    player.autoshld    = off;
  590.                             player.mgun    = off;    player.bomb              = off;
  591.                             player.luck     = off;    player.longshot     = off;
  592.                             player.retros  = off;
  593.  
  594.                             player.x         = (MAX_WIN_X + MIN_WIN_Y) >> 1;
  595.                             player.y         = (MAX_WIN_Y + MIN_WIN_Y) >> 1;
  596.                             player.dx         = 0;
  597.                             player.dy         = 0;
  598.                             player.status     = active;
  599.                             player.dir         = 0;
  600.  
  601.                             SetWriteBank(11);
  602.                             sprintf(out,"Score: %6ld  Bonus: %6ld  Lives: %2i  Shields:"
  603.                                           ,(long)player.score,(long)5000,player.lives);
  604.                             Alpha(out,0,0);
  605.  
  606.                             DrawPlayer();
  607.  
  608.                             for (i = 0; i < MAXROCK; i++)
  609.                                 if (rock[i].status == active)
  610.                                     DrawRock(i);
  611.                         }
  612.                     }
  613.                 }
  614.                 if (complete)
  615.                     NewLevel();
  616.                 else if (player.status == dieing)
  617.                     DeathScreen();
  618.             }
  619.  
  620.             Disable_Key_Interrupt();
  621.         }
  622.     }
  623.  
  624.     De_Init_Sound();
  625.     De_Init_Graphics();
  626.  
  627.     exit(0);
  628. }
  629.  
  630. // Because we don't bother picking up the background when we draw
  631. // our sprites, the stars are going to be wiped out.  To fix this,
  632. // instead of putting in more delay loops, we simply redraw the stars
  633. // whenever we have extra time.  This function draws on star each
  634. // time it is called, then draws the next on the next time.
  635. void DrawStar(void)
  636. {
  637.     static int i = 0;
  638.  
  639. //    outport(0x3CD,star[i].y>>6);
  640.     SetWriteBank(star[i].y>>6);
  641.  
  642.     putpixel(star[i].x, star[i].y,star[i].col);
  643.  
  644.     if (++i >= NUMSTARS)
  645.         i = 0;
  646. }
  647.  
  648. void DeathScreen(void)
  649. {
  650.     char out[50];
  651.     union REGS regs;
  652.     struct SREGS sregs;
  653.  
  654.     cleardevice();
  655.     regs.x.ax = 0x1012;
  656.     regs.x.bx = 0;
  657.     regs.x.cx = 255;
  658.  
  659.     regs.x.dx = FP_OFF( (int far *)&pal[0] );
  660.     sregs.es  = FP_SEG( (int far *)&pal[0] );
  661.  
  662.     int86x(0x10, ®s, ®s, &sregs);
  663.  
  664.     SetWriteBank(5);
  665.     sprintf(out,"Ooops!  You died!  Bummer, eh?");
  666.     Alpha(out,30,2);
  667.     sprintf(out,"Final Score: %ld",player.score);
  668.     Alpha(out,30,4);
  669.     SetWriteBank(6);
  670.     sprintf(out,"[Press *FIRE* to return to main menu]");
  671.     Alpha(out,27,2);
  672.  
  673.     while (k.fire != PRESSED)
  674.     {}
  675.  
  676.     return;
  677. }
  678.  
  679. void NewLevel(void)
  680. {
  681.     int i;
  682.     union REGS regs;
  683.     struct SREGS sregs;
  684.  
  685.     char out[50];
  686.  
  687.     cleardevice();
  688.     regs.x.ax = 0x1012;
  689.     regs.x.bx = 0;
  690.     regs.x.cx = 255;
  691.  
  692.     regs.x.dx = FP_OFF( (int far *)&pal[0] );
  693.     sregs.es  = FP_SEG( (int far *)&pal[0] );
  694.  
  695.     int86x(0x10, ®s, ®s, &sregs);
  696.  
  697.     SetWriteBank(5);
  698.     sprintf(out,"Level %i completed!",level);
  699.     Alpha(out,35,2);
  700.     sprintf(out,"Bonus: %ld",(long)0);
  701.     Alpha(out,35,3);
  702.     sprintf(out,"Score: %ld",player.score);
  703.     Alpha(out,35,5);
  704.  
  705.     SetWriteBank(6);
  706.     sprintf(out,"[Press *FIRE* to begin next level]");
  707.     Alpha(out,25,2);
  708.  
  709.     while (k.fire != PRESSED)
  710.     {}
  711.  
  712.     cleardevice();
  713.     regs.x.ax = 0x1012;
  714.     regs.x.bx = 0;
  715.     regs.x.cx = 255;
  716.  
  717.     regs.x.dx = FP_OFF( (int far *)&pal[0] );
  718.     sregs.es  = FP_SEG( (int far *)&pal[0] );
  719.  
  720.     int86x(0x10, ®s, ®s, &sregs);
  721.  
  722.     level++;
  723.  
  724.     CalcNewLevel();
  725.  
  726.     for (i = 0; i < MAXBUL; i++)
  727.         bul[i].status = inactive;
  728.  
  729.     SetWriteBank(11);
  730.  
  731.     for (i = 16; i < 1040; i++)
  732.     {
  733.         putpixel(i,46,12);
  734.         putpixel(i,47,13);
  735.         putpixel(i,48,12);
  736.     }
  737.  
  738.     sprintf(out,"Score: %6ld  Bonus: %6ld  Lives: %2i  Shields:"
  739.                       ,(long)player.score,(long)5000,player.lives);
  740.     Alpha(out,0,0);
  741.  
  742.     drawscreen();
  743.  
  744.     DrawPlayer();
  745.     for (i = 0; i < MAXROCK; i++)
  746.         if (rock[i].status == active)
  747.             DrawRock(i);
  748.  
  749.     return;
  750. }
  751.  
  752. int DoMenu(void)
  753. {
  754.     char key = 0;
  755.  
  756.     while (kbhit())
  757.         getch();
  758.  
  759.     draw_menu();
  760.  
  761.     while (key != 27)
  762.     {
  763.         key = getch();
  764.         switch (key)
  765.         {
  766.             case 27  :
  767.             case 'q' :
  768.             case 'Q' :
  769.                 return(1);
  770.                 break;
  771.             case 'p' :
  772.             case 'P' :
  773.                 return(0);
  774.                 break;
  775.             case 'i' :
  776.             case 'I' :
  777.                 instruct();
  778.                 draw_menu();
  779.                 break;
  780.         }
  781.     }
  782.     return(1);
  783. }
  784.  
  785. void instruct(void)
  786. {
  787.     char text[1000];
  788.  
  789.     cleardevice();
  790.  
  791.     set_intro_pal();
  792.  
  793.     SetWriteBank(2);
  794.     sprintf(text,"INSTRUCTIONS:\n\n\
  795.       These are pretty simple since this is the first release\n\
  796.       (but *NOT* final!) of this game!  Here they are:\n\n");
  797.     Alpha(text,10,2);
  798.     SetWriteBank(3);
  799.     sprintf(text,"    Keypad 4 (left-arrow)  rotates counter-clockwise.\n\
  800.           Keypad 6 (right-arrow) rotates clockwise.\n\
  801.           Keypad 8 (up-arrow) thrusts.\n\
  802.           [LEFT-SHIFT] raises shields.\n");
  803.     Alpha(text,10,2);
  804.     SetWriteBank(4);
  805.     sprintf(text,"    [CTRL] fires your Mega-Nuko-Death-O-Plenty-Blasters.\n\n\
  806.       Collect little floaty things to gain more items such as: (not working)\n");
  807.     Alpha(text,10,2);
  808.  
  809.     SetWriteBank(5);
  810.     sprintf(text,"    Rapid-Fire     Auto-Shields    Triple-Shot\n\
  811.           Retro-Rockets  Long-Shot       Luck\n\
  812.           and Mega-Bombs!\n\
  813.          Have Fun!");
  814.     Alpha(text,10,2);
  815.  
  816.     SetWriteBank(7);
  817.     sprintf(text,"NOTE:  This game is *FREEWARE*!  Public Domain.\n\
  818. You may distribute this game to anyone on the planet as long as you\n\
  819. don't charge them a cent.");
  820.     Alpha(text,10,2);
  821.  
  822.     SetWriteBank(8);
  823.     sprintf(text,"Feedback on this game is welcome!  Anything from\n\
  824. \"This game is *GREAt*\" to \"This is the worst game I've played\n\
  825. in my entire life!\"  Money wouldn't be refused either. %");
  826.     Alpha(text,10,2);
  827.  
  828.     SetWriteBank(9);
  829.     sprintf(text,"I may be reached at:\n\
  830.           Augusto Roman\n\
  831.           4865 Las Alturas\n\
  832.           Las Cruces, NM, 88011");
  833.     Alpha(text,10,2);
  834.  
  835.     SetWriteBank(10);
  836.     sprintf(text,"or via e-mail at:  aroman@dante.nmsu.edu\n\n\
  837. % C SOURCE CODE AVAILABLE UPON REQUEST! %");
  838.     Alpha(text,10,2);
  839.  
  840.     getch();
  841. }
  842.  
  843. void draw_menu(void)
  844. {
  845.     int i;
  846.     unsigned char pal2[768];
  847.     unsigned char out[100];
  848.  
  849.     union REGS regs;
  850.     struct SREGS sregs;
  851.  
  852.     FILE *in_file;
  853.  
  854.     cleardevice();
  855.  
  856.     for (i = 0; i < 768; i++)
  857.         pal2[i] = 0;
  858.  
  859.     regs.x.ax = 0x1012;
  860.     regs.x.bx = 0;
  861.     regs.x.cx = 255;
  862.  
  863.     regs.x.dx = FP_OFF( (int far *)&pal2[0] );
  864.     sregs.es  = FP_SEG( (int far *)&pal2[0] );
  865.  
  866.     int86x(0x10, ®s, ®s, &sregs);
  867.  
  868. //    display_raw(192,184,"intro1.raw",320,200);
  869.     display_raw(192,184,"fil012.dat",320,200);
  870. //    display_raw(512,184,"intro2.raw",320,200);
  871.     display_raw(512,184,"fil013.dat",320,200);
  872. //    display_raw(192,384,"intro3.raw",320,200);
  873.     display_raw(192,384,"fil014.dat",320,200);
  874. //    display_raw(512,384,"intro4.raw",320,200);
  875.     display_raw(512,384,"fil015.dat",320,200);
  876.  
  877.     set_intro_pal();
  878.  
  879.     setcolor(192);
  880.     rect(350,655,550,705);
  881.  
  882.     SetWriteBank(0);
  883.     for (i = 0; i < 1024; i++)
  884.         putpixel(i,5,192);
  885.     for (i = 0; i < 1024; i++)
  886.         putpixel(i,40,192);
  887.     sprintf(out,"  DeathRoids!!\n   Ver. 0.99b\n\nBy Augusto Roman");
  888.     Alpha(out,33,2);
  889.  
  890.     SetWriteBank(10);
  891.     sprintf(out,"P)lay new game!\nI)instructions\nQ)uit");
  892.     Alpha(out,30,3);
  893.  
  894.     return;
  895. }
  896.  
  897. void set_intro_pal(void)
  898. {
  899.     int i;
  900.     union REGS regs;
  901.     struct SREGS sregs;
  902.     char pal2[768];
  903.  
  904.     FILE *in_file;
  905.  
  906. //    in_file = fopen("intro.pal","rb");
  907.     in_file = fopen("fil016.dat","rb");
  908.     for (i = 0; i < 768; i++)
  909.         pal2[i] = getc(in_file);
  910.     fclose(in_file);
  911.  
  912.     for (i = 192; i < 224; i++)
  913.     {
  914.         pal2[i*3  ] = 63;
  915.         pal2[i*3+1] = (i - 192)*2;
  916.         pal2[i*3+2] = 0;
  917.     }
  918.     for (i = 224; i < 250; i++)
  919.     {
  920.         pal2[i*3  ] = 63 - (i - 224)*2;
  921.         pal2[i*3+1] = 63;
  922.         pal2[i*3+2] = 0;
  923.     }
  924.  
  925.     pal2[0] = pal2[1] = pal2[2] = 0;
  926.     pal2[11*3  ] = 0;
  927.     pal2[11*3+1] = 63;
  928.     pal2[11*3+2] = 0;
  929.  
  930.     regs.x.ax = 0x1012;
  931.     regs.x.bx = 0;
  932.     regs.x.cx = 255;
  933.  
  934.     regs.x.dx = FP_OFF( (int far *)&pal2[0] );
  935.     sregs.es  = FP_SEG( (int far *)&pal2[0] );
  936.  
  937.     int86x(0x10, ®s, ®s, &sregs);
  938.  
  939.     return;
  940. }
  941.  
  942. /*
  943. int getkey(void)
  944. {
  945.  int key, lo, hi;
  946.  
  947.  key = bioskey(0);
  948.  lo = key & 0X00FF;
  949.  hi = (key & 0XFF00) >> 8;
  950.  return((lo == 0) ? hi + 256 : lo);
  951. }
  952.  
  953.  
  954. void chkkey(void)
  955. {
  956.     int ch;
  957.     ch = bioskey(0);
  958.     ch = (ch & 0x00FF) == 0 ? (ch & 0xFF00) + 256 : (ch & 0x00FF);
  959.  
  960.     k.thrust = k.left = k.right = k.fire = k.shield = UNPRESSED;
  961.  
  962.     if (ch == 328)
  963.         k.thrust = PRESSED;
  964.     else if (ch == 331)
  965.         k.left = PRESSED;
  966.     else if (ch == 333)
  967.         k.right = PRESSED;
  968.     else if (ch == 'z' || ch == 'Z')
  969.         k.fire = PRESSED;
  970.     else
  971.         k.shield = PRESSED;
  972. }
  973. */
  974. void Thrust(void)
  975. {
  976.     player.dx += dcost[player.dir];
  977.     player.dy += dsint[player.dir];
  978.  
  979.     if (player.dx >  MAXSPEED)
  980. //        player.dx =  MAXSPEED;
  981.         player.dx -= dcost[player.dir];
  982.     else if (player.dx < -MAXSPEED)
  983. //        player.dx = -MAXSPEED;
  984.         player.dx -= dcost[player.dir];
  985.     if (player.dy >  MAXSPEED)
  986. //        player.dy =  MAXSPEED;
  987.         player.dy -= dsint[player.dir];
  988.     else if (player.dy < -MAXSPEED)
  989. //        player.dy = -MAXSPEED;
  990.         player.dy -= dsint[player.dir];
  991.  
  992.     if (player.retros == on)
  993.     {
  994.         player.dx -= player.dx >> 2;
  995.         player.dy -= player.dy >> 2;
  996.     }
  997.  
  998.     return;
  999. }
  1000.  
  1001. void MovePlayer(void)
  1002. {
  1003.     static int shld_flag = UNPRESSED;
  1004.  
  1005.     if (shld_flag == PRESSED)
  1006.         eraseimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1007.     else
  1008.         eraseimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1009.  
  1010.     if (k.left == PRESSED)                                    /* turn left */
  1011.         if ( ( player.dir -= TURNRATE ) < 0)
  1012.             player.dir += 360;
  1013.  
  1014.     if (k.right == PRESSED)                         /* turn right */
  1015.         if ( ( player.dir += TURNRATE ) >= 360)
  1016.             player.dir -= 360;
  1017.  
  1018.     player.x += player.dx >> FSHIFT;
  1019.     player.y += player.dy >> FSHIFT;
  1020.  
  1021.     CheckPlayer();
  1022.  
  1023.     if (player.shield > 0)
  1024.         shld_flag = k.shield;
  1025.     else
  1026.     {
  1027.         shld_flag = UNPRESSED;
  1028.         k.shield = UNPRESSED;
  1029.     }
  1030.  
  1031.     if (shld_flag == PRESSED)
  1032.         putimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1033.     else
  1034.         putimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1035.  
  1036.     return;
  1037. }
  1038.  
  1039. void ErasePlayer(void)
  1040. {
  1041.     if (k.shield == PRESSED)
  1042.         eraseimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1043.     else
  1044.         eraseimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1045.     return;
  1046. }
  1047.  
  1048. void DrawPlayer(void)
  1049. {
  1050.     if (k.shield == PRESSED)
  1051.         putimage(ship_shld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1052.     else
  1053.         putimage(ship_noshld_pic[player.dir / 9],player.x-32,player.y-32, SHIP_SIZE);
  1054.  
  1055.     return;
  1056. }
  1057.  
  1058. void MoveRock(short int rocknum)
  1059. {
  1060.     EraseRock(rocknum);
  1061. //    DrawRock(rocknum);
  1062.  
  1063.     rock[rocknum].x += rock[rocknum].dx >> FSHIFT;
  1064.     rock[rocknum].y += rock[rocknum].dy >> FSHIFT;
  1065.  
  1066.     CheckRock(rocknum);
  1067.  
  1068.     if (rock[rocknum].status == active)
  1069.         DrawRock(rocknum);
  1070.  
  1071.     return;
  1072. }
  1073.  
  1074. void MoveBul(short int bulnum)
  1075. {
  1076.     EraseBul(bulnum);
  1077. //    DrawBul(bulnum);
  1078.  
  1079.     CheckBul(bulnum);
  1080.  
  1081.     bul[bulnum].x += bul[bulnum].dx >> FSHIFT;
  1082.     bul[bulnum].y += bul[bulnum].dy >> FSHIFT;
  1083.  
  1084.     DrawBul(bulnum);
  1085. }
  1086.  
  1087. void CheckPlayer(void)
  1088. {
  1089.     if (player.x > MAX_WIN_X)
  1090.         player.x = MIN_WIN_X;
  1091.     else if (player.x < MIN_WIN_X)
  1092.         player.x = MAX_WIN_X;
  1093.     if (player.y > MAX_WIN_Y)
  1094.         player.y = MIN_WIN_Y;
  1095.     else if (player.y < MIN_WIN_Y)
  1096.         player.y = MAX_WIN_Y;
  1097.  
  1098.     return;
  1099. }
  1100.  
  1101. void CheckRock(short int rocknum)
  1102. {
  1103.     short int radius;
  1104.  
  1105.     switch (rock[rocknum].size)
  1106.     {
  1107.         case large:
  1108.             radius = 45;
  1109.             break;
  1110.         case med:
  1111.             radius = 40;
  1112.             break;
  1113.         case small:
  1114.             radius = 35;
  1115.             break;
  1116.     }
  1117.  
  1118.     if (rock[rocknum].status != active)
  1119.         return;
  1120.  
  1121.     if (rock[rocknum].x > MAX_WIN_X)
  1122.         rock[rocknum].x = MIN_WIN_X;
  1123.     else if (rock[rocknum].x < MIN_WIN_X)
  1124.         rock[rocknum].x = MAX_WIN_X;
  1125.     if (rock[rocknum].y > MAX_WIN_Y)
  1126.         rock[rocknum].y = MIN_WIN_Y;
  1127.     else if (rock[rocknum].y < MIN_WIN_Y)
  1128.         rock[rocknum].y = MAX_WIN_Y;
  1129.  
  1130.     if (abs(rock[rocknum].x - player.x) < radius)
  1131.         if (abs(rock[rocknum].y - player.y) < radius)
  1132.         {
  1133.             if (k.shield == PRESSED && player.shield > 0)
  1134.             {
  1135.                 if (sound_mode == on)
  1136.                 {
  1137.                     VocStop();
  1138.                     VocPlay((char far *)soundb[HITROCK]);
  1139.                 }
  1140.                 KillRock(rocknum);
  1141.                 rock[rocknum].status = inactive;
  1142. //                EraseRock(rocknum);
  1143. //                DrawRock(rocknum);
  1144.             }
  1145.             else
  1146.             {
  1147.                 if (sound_mode == on)
  1148.                 {
  1149.                     VocStop();
  1150.                     VocPlay((char far *)soundb[DIE]);
  1151.                 }
  1152.                 player.status = dieing;
  1153.                 DrawRock(rocknum);
  1154. //                gotoxy(1,1);
  1155. //                printf("*** HIT BY ROCK #%3d - [%3.2f,%3.2f], status: %3d\n ",
  1156. //                          rocknum, rock[rocknum].x, rock[rocknum].y,
  1157. //                          rock[rocknum].status);
  1158.             }
  1159.         }
  1160.  
  1161.     if (rock[rocknum].framedelay++ >= ROCK_DELAY_RATE)
  1162.     {
  1163.         if (++rock[rocknum].curframe >= NUM_ROCK_PICS )
  1164.             rock[rocknum].curframe = 0;
  1165.         rock[rocknum].framedelay = 0;
  1166.     }
  1167.  
  1168.     return;
  1169. }
  1170.  
  1171. void CheckBul(short int bulnum)
  1172. {
  1173.     int i;
  1174.  
  1175.     if (bul[bulnum].lcount++ > 50)
  1176.     {
  1177.         bul[bulnum].status = inactive;
  1178.         return;
  1179.     }
  1180.  
  1181.     for (i = 0; i < MAXROCK; i++)
  1182.     {
  1183.         if (rock[i].status == active)
  1184.             if (abs(bul[bulnum].x - rock[i].x) < (8 << rock[i].size)+2)
  1185.                 if (abs(bul[bulnum].y - rock[i].y) < (8 << rock[i].size)+2)
  1186.                 {
  1187.                     if (sound_mode == on)
  1188.                     {
  1189.                         VocStop();
  1190.                         VocPlay((char far *)soundb[HITROCK]);
  1191.                     }
  1192.                     KillRock(i);
  1193.                     rock[i].status = inactive;
  1194.                     bul[bulnum].status = inactive;
  1195.                     EraseBul(bulnum);
  1196. //                    EraseRock(i);
  1197. //                    DrawBul(bulnum);
  1198. //                    DrawRock(i);
  1199.                     player.score += 250 * rock[i].size;
  1200.                     break;
  1201.                 }
  1202.     }
  1203.  
  1204.     if (bul[bulnum].x > MAX_WIN_X)
  1205.         bul[bulnum].x = MIN_WIN_X;
  1206.     else if (bul[bulnum].x < MIN_WIN_X)
  1207.         bul[bulnum].x = MAX_WIN_X;
  1208.     if (bul[bulnum].y > MAX_WIN_Y)
  1209.         bul[bulnum].y = MIN_WIN_Y;
  1210.     else if (bul[bulnum].y < MIN_WIN_Y)
  1211.         bul[bulnum].y = MAX_WIN_Y;
  1212.  
  1213.     if (++bul[bulnum].curframe >= NUM_BUL_PICS)
  1214.         bul[bulnum].curframe = 0;
  1215.  
  1216.     return;
  1217. }
  1218.  
  1219. void FireBul(void)
  1220. {
  1221.     int i;
  1222.  
  1223.     for (i = 0; i < MAXBUL; i++)
  1224.         if (bul[i].status == inactive)
  1225.         {
  1226.             bul[i].dx = player.dx + 6*dcost[player.dir];
  1227.             bul[i].dy = player.dy + 6*dsint[player.dir];
  1228.             bul[i].x = player.x + ((3*dcost[player.dir])>>FSHIFT);
  1229.             bul[i].y = player.y + ((3*dsint[player.dir])>>FSHIFT);
  1230.             bul[i].lcount = 0;
  1231.             bul[i].status = active;
  1232.             bul[i].curframe = 0;
  1233.             DrawBul(i);
  1234.             if (sound_mode == on)
  1235.             {
  1236.                 VocStop();
  1237.                 VocPlay((char far *)soundb[FIRE]);
  1238.             }
  1239.             break;
  1240.         }
  1241.  
  1242.     return;
  1243. }
  1244.  
  1245. void NewRock(int x, int y, sizetype size)
  1246. {
  1247.     int i;
  1248.  
  1249.     for (i = 0; i < MAXROCK; i++)
  1250.         if (rock[i].status == inactive)
  1251.         {
  1252.             rock[i].x = x;
  1253.             rock[i].y = y;
  1254.             rock[i].dx = ((random(10000)-5000) / 1000)*FSCALE;
  1255.             rock[i].dy = ((random(10000)-5000) / 1000)*FSCALE;
  1256.             rock[i].size = size;
  1257.             rock[i].status = active;
  1258.             rock[i].curframe = random(NUM_ROCK_PICS);
  1259.             rock[i].framedelay = 0;
  1260.             DrawRock(i);
  1261.             break;
  1262.         }
  1263.     return;
  1264. }
  1265.  
  1266. void KillRock(short int rocknum)
  1267. {
  1268.     int i;
  1269.  
  1270.     EraseRock(rocknum);
  1271. //    DrawRock(rocknum);
  1272.     rock[rocknum].status = dieing;
  1273.  
  1274.     if (rock[rocknum].size == small)
  1275.         return;
  1276.  
  1277.     for (i = 0; i < rock[rocknum].size; i++)
  1278.         NewRock(rock[rocknum].x, rock[rocknum].y, rock[rocknum].size-1);
  1279.  
  1280.     return;
  1281. }
  1282.  
  1283. void DoKeys(void)
  1284. {
  1285.     static flag fire_flag = UNPRESSED;
  1286.     static int wep_wait = 0;
  1287.  
  1288.     /*** Weapon System ***/
  1289.  
  1290.     if ((fire_flag == UNPRESSED || player.mgun) && wep_wait++ > 2)
  1291.         if (k.fire == PRESSED)
  1292.         {
  1293.             FireBul();
  1294.             wep_wait = 0;
  1295.             fire_flag = PRESSED;
  1296.         }
  1297.     if (k.fire == UNPRESSED)
  1298.         fire_flag = UNPRESSED;
  1299.  
  1300.     if (wep_wait > 50)
  1301.         wep_wait = 50;
  1302.  
  1303.     /*** Ship Control ***/
  1304.  
  1305. //    if (k.left == PRESSED)                                    /* turn left */
  1306. //        if ( ( player.dir -= TURNRATE ) < 0)
  1307. //            player.dir += 360;
  1308.  
  1309. //    if (k.right == PRESSED)                         /* turn right */
  1310. //        if ( ( player.dir += TURNRATE ) >= 360)
  1311. //            player.dir -= 360;
  1312.  
  1313.     if (k.thrust == PRESSED)                                        /* thrust */
  1314.         Thrust();
  1315.  
  1316.     if (k.shield == PRESSED)
  1317.     {
  1318.         if (player.shield > 0)
  1319.             player.shield -= 2;
  1320.         else
  1321.             k.shield = UNPRESSED;
  1322.     }
  1323.  
  1324.     return;
  1325. }
  1326.  
  1327. void EraseBul(short int bulnum)
  1328. {
  1329.  
  1330. //    putimage(bullet_back[bulnum],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
  1331.  
  1332.     eraseimage(bullet_pic[bul[bulnum].curframe],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
  1333.  
  1334.     return;
  1335. }
  1336.  
  1337. void DrawBul(short int bulnum)
  1338. {
  1339.  
  1340. //    getimage(bullet_back[bulnum],bul[bulnum].x-8,bul[bulnum].y-8,16);
  1341.  
  1342.     if (bul[bulnum].status == active)
  1343.         putimage(bullet_pic[bul[bulnum].curframe],bul[bulnum].x-8,bul[bulnum].y-8,BUL_SIZE);
  1344.  
  1345.     return;
  1346. }
  1347.  
  1348. void EraseRock(short int rocknum)
  1349. {
  1350.     switch (rock[rocknum].size)
  1351.     {
  1352.         case large:
  1353. //            putimage(aster_back[rocknum],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
  1354.             eraseimage(aster_pic[rock[rocknum].curframe],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
  1355.             break;
  1356.         case med:
  1357.             eraseimage(med_aster_pic[rock[rocknum].curframe],rock[rocknum].x-16, rock[rocknum].y-16,ROCK_MD_SIZE);
  1358.             break;
  1359.         case small:
  1360.             eraseimage(small_aster_pic[rock[rocknum].curframe],rock[rocknum].x-8, rock[rocknum].y-8,ROCK_SM_SIZE);
  1361.             break;
  1362.     }
  1363.  
  1364.     return;
  1365. }
  1366.  
  1367. void DrawRock(short int rocknum)
  1368. {
  1369.     switch (rock[rocknum].size)
  1370.     {
  1371.         case large:
  1372. //            getimage(aster_back[rocknum],rock[rocknum].x-32, rock[rocknum].y-32,64);
  1373.             putimage(aster_pic[rock[rocknum].curframe],rock[rocknum].x-32, rock[rocknum].y-32,ROCK_LG_SIZE);
  1374.             break;
  1375.         case med:
  1376. //            getimage(aster_back[rocknum],rock[rocknum].x-16, rock[rocknum].y-16,32);
  1377.             putimage(med_aster_pic[rock[rocknum].curframe],rock[rocknum].x-16, rock[rocknum].y-16,ROCK_MD_SIZE);
  1378.             break;
  1379.         case small:
  1380. //            getimage(aster_back[rocknum],rock[rocknum].x-8, rock[rocknum].y-8,16);
  1381.             putimage(small_aster_pic[rock[rocknum].curframe],rock[rocknum].x-8, rock[rocknum].y-8,ROCK_SM_SIZE);
  1382.             break;
  1383.     }
  1384.  
  1385.     return;
  1386. }
  1387.  
  1388. void drawscreen(void)
  1389. {
  1390. //    int i,j;
  1391.     char output[30];
  1392. //    unsigned long i;
  1393.  
  1394. //    outportb(0x3CD,750>>6);
  1395.     SetWriteBank(750>>6);
  1396. /*
  1397.     for (i = 0; i < 1023; i++)
  1398.     {
  1399.         putpixel(i,750,22);
  1400.         putpixel(i,751,25);
  1401.         putpixel(i,752,22);
  1402.     }
  1403. */
  1404. //    sprintf(output,"Score: %6ld  Bonus: %6ld  Lives: %2i  Shields:"
  1405. //                      ,(long)player.score,(long)5000,player.lives);
  1406.  
  1407.     sprintf(output,"%6ld",player.score);
  1408.     Alpha(output,7,0);
  1409.  
  1410.     sprintf(output,"%6ld",(long)5000);
  1411.     Alpha(output,22,0);
  1412.  
  1413. //    i = farcoreleft();
  1414. //    sprintf(output,"Core Left: %6ld",i);
  1415. //    Alpha(output,65,0);
  1416.  
  1417.     drawshields(player.shield);
  1418.  
  1419. /*
  1420.     Alpha(output,0,0);
  1421.  
  1422.     sprintf(output,"Dir: %4i",player.dir);
  1423.  
  1424.     Alpha(output,70,0);
  1425.  
  1426.     drawshields(player.shield);
  1427. */
  1428.     return;
  1429. }
  1430.  
  1431. void drawshields(int shields)
  1432. {
  1433.     int i,j,col,temp;
  1434.  
  1435.     temp = shields + 604;
  1436.     col = shields/20+1;
  1437.  
  1438.     for (i = 604; i < temp; i += 2)
  1439.         for (j = 755; j < 765; j += 2)
  1440.             putpixel(i,j,col);
  1441.  
  1442.     for (i = i; i < 804; i += 2)
  1443.         for (j = 755; j < 765; j += 2)
  1444.             putpixel(i,j,14);
  1445.  
  1446.     return;
  1447. }
  1448.  
  1449. void Alpha(char s[], int x, int y)
  1450. {
  1451.     int i, xoff = 0;
  1452.  
  1453.     i = -1;
  1454.     while (s[++i] != '\0')
  1455.     {
  1456.         if (s[i] > 96)
  1457.             s[i] -= 32;
  1458.         else if (s[i] == 10)
  1459.         {
  1460.             y++;
  1461.             xoff = -1;
  1462.         }
  1463.         PutLetter (s[i], x+xoff, y);
  1464.         xoff++;
  1465.     }
  1466.     return;
  1467. }
  1468.  
  1469.  
  1470. void PutLetter (int l, int x, int y)
  1471. {
  1472.     switch (l)
  1473.     {
  1474.         case 32 : drawobject(spc,x,y); break;
  1475.         case 33 : drawobject(exc,x,y); break;
  1476.         case 34 : drawobject(quot,x,y); break;
  1477.         case 37 : drawobject(hapy,x,y); break;
  1478.         case 39 : drawobject(apos,x,y); break;
  1479.         case 40 : drawobject(lpar,x,y); break;
  1480.         case 41 : drawobject(rpar,x,y); break;
  1481.         case 42 : drawobject(starc,x,y); break;
  1482.         case 44 : drawobject(coma,x,y); break;
  1483.         case 45 : drawobject(dsh,x,y); break;
  1484.         case 46 : drawobject(prd,x,y); break;
  1485.         case 48 : drawobject(n0,x,y); break;
  1486.         case 49 : drawobject(n1,x,y); break;
  1487.         case 50 : drawobject(n2,x,y); break;
  1488.         case 51 : drawobject(n3,x,y); break;
  1489.         case 52 : drawobject(n4,x,y); break;
  1490.         case 53 : drawobject(n5,x,y); break;
  1491.         case 54 : drawobject(n6,x,y); break;
  1492.         case 55 : drawobject(n7,x,y); break;
  1493.         case 56 : drawobject(n8,x,y); break;
  1494.         case 57 : drawobject(n9,x,y); break;
  1495.         case 58 : drawobject(col,x,y); break;
  1496.         case 63 : drawobject(ques,x,y); break;
  1497.         case 64 : drawobject(ampr,x,y); break;
  1498.         case 65 : drawobject(aa,x,y); break;
  1499.         case 66 : drawobject(bb,x,y); break;
  1500.         case 67 : drawobject(cc,x,y); break;
  1501.         case 68 : drawobject(dd,x,y); break;
  1502.         case 69 : drawobject(ee,x,y); break;
  1503.         case 70 : drawobject(ff,x,y); break;
  1504.         case 71 : drawobject(gg,x,y); break;
  1505.         case 72 : drawobject(hh,x,y); break;
  1506.         case 73 : drawobject(ii,x,y); break;
  1507.         case 74 : drawobject(jj,x,y); break;
  1508.         case 75 : drawobject(kk,x,y); break;
  1509.         case 76 : drawobject(ll,x,y); break;
  1510.         case 77 : drawobject(mm,x,y); break;
  1511.         case 78 : drawobject(nn,x,y); break;
  1512.         case 79 : drawobject(oo,x,y); break;
  1513.         case 80 : drawobject(pp,x,y); break;
  1514.         case 81 : drawobject(qq,x,y); break;
  1515.         case 82 : drawobject(rr,x,y); break;
  1516.         case 83 : drawobject(ss,x,y); break;
  1517.         case 84 : drawobject(tt,x,y); break;
  1518.         case 85 : drawobject(uu,x,y); break;
  1519.         case 86 : drawobject(vv,x,y); break;
  1520.         case 87 : drawobject(ww,x,y); break;
  1521.         case 88 : drawobject(xx,x,y); break;
  1522.         case 89 : drawobject(yy,x,y); break;
  1523.         case 90 : drawobject(zz,x,y); break;
  1524.         case 91 : drawobject(lbrk,x,y); break;
  1525.         case 93 : drawobject(rbrk,x,y); break;
  1526.         default :
  1527.             break;
  1528.     }
  1529.     return;
  1530. }
  1531.  
  1532. void drawobject(signed char far object[],int x,int y)
  1533. {
  1534.     int i = 0,j = 1;
  1535.  
  1536.     int sx, sy;
  1537.  
  1538.     sx = 4 + x * 12;
  1539.     sy = 755 + y * 12;
  1540.  
  1541.     do
  1542.     {
  1543.             if (object[i] == 0)
  1544. //                putpixel(sx+j*2,sy,120);
  1545.                 putpixel(sx+j*2,sy,0);
  1546.             else if (object[i] == 1)
  1547. //                putpixel(sx+j*2,sy,48);
  1548.                 putpixel(sx+j*2,sy,11);
  1549.             else if (object[i] == -2)
  1550.             {
  1551.                 sy+=2;
  1552.                 j = 0;
  1553.             }
  1554.             j++;
  1555.             i++;
  1556.     }
  1557.     while (object[i] != -3);
  1558.  
  1559.     return;
  1560. }
  1561.  
  1562. void Init_Game(void)
  1563. {
  1564.     int i;
  1565.     double pi = 3.141592654;
  1566.     char output[50];
  1567.  
  1568.     union REGS regs;
  1569.     struct SREGS sregs;
  1570.  
  1571.     randomize();
  1572.  
  1573.     cleardevice();
  1574.  
  1575.     regs.x.ax = 0x1012;
  1576.     regs.x.bx = 0;
  1577.     regs.x.cx = 255;
  1578.     regs.x.dx = FP_OFF( (int far *)&pal[0] );
  1579.     sregs.es  = FP_SEG( (int far *)&pal[0] );
  1580.     int86x(0x10, ®s, ®s, &sregs);
  1581.  
  1582.     for (i = 0; i < 360; i++)
  1583.     {
  1584.         dsint[i] = (sin((float)i*pi/180.0))*FSCALE;
  1585.         dcost[i] = (cos((float)i*pi/180.0))*FSCALE;
  1586.     }
  1587.  
  1588.     keyOpt.left_press         = 75;
  1589.     keyOpt.left_unpress         = 203;
  1590.     keyOpt.right_press         = 77;
  1591.     keyOpt.right_unpress     = 205;
  1592.     keyOpt.thrust_press         = 72;
  1593.     keyOpt.thrust_unpress     = 200;
  1594.     keyOpt.shield_press         = 42;
  1595.     keyOpt.shield_unpress    = 170;
  1596.     keyOpt.fire_press            = 0;
  1597.     keyOpt.fire_unpress        = 0;
  1598.  
  1599.     level = 1;
  1600.  
  1601.     player.shield     = 200;
  1602.     player.lives      = 3;
  1603.     player.score      = 0;
  1604.     player.trishot = off;    player.autoshld    = off;
  1605.     player.mgun    = off;    player.bomb              = off;
  1606.     player.luck     = off;    player.longshot     = off;
  1607.     player.retros  = off;
  1608.  
  1609.     CalcNewLevel();
  1610.  
  1611. //    outportb(0x3CD,750>>6);
  1612.     SetWriteBank(11);
  1613.  
  1614.     for (i = 16; i < 1040; i++)
  1615.     {
  1616.         putpixel(i,46,12);
  1617.         putpixel(i,47,13);
  1618.         putpixel(i,48,12);
  1619.     }
  1620.  
  1621.     sprintf(output,"Score: %6ld  Bonus: %6ld  Lives: %2i  Shields:"
  1622.                       ,(long)player.score,(long)5000,player.lives);
  1623.     Alpha(output,0,0);
  1624.  
  1625.     drawscreen();
  1626.  
  1627.     DrawPlayer();
  1628.     for (i = 0; i < MAXROCK; i++)
  1629.         if (rock[i].status == active)
  1630.             DrawRock(i);
  1631.  
  1632.     return;
  1633. }
  1634.  
  1635. void CalcNewLevel(void)
  1636. {
  1637.     int i;
  1638.     int centerx, centery;
  1639.     int tempx, tempy;
  1640.     int numrocks;
  1641.  
  1642.     centerx             = (MAX_WIN_X + MIN_WIN_Y) >> 1;
  1643.     centery             = (MAX_WIN_Y + MIN_WIN_Y) >> 1;
  1644.     player.x         = centerx;
  1645.     player.y         = centery;
  1646.     player.dx         = 0;
  1647.     player.dy         = 0;
  1648.     player.status     = active;
  1649.     player.dir         = 0;
  1650.  
  1651.     numrocks = (level/2)+2;
  1652.  
  1653.     for (i = 0; i < MAXROCK; i++)
  1654.         rock[i].status = inactive;
  1655.  
  1656.     for (i = 0; i < MAXBUL; i++)
  1657.         bul[i].status = inactive;
  1658.  
  1659.     for (i = 0; i < numrocks; i++)
  1660.     {
  1661.         while (tempx > centerx-centerx*0.10 && tempx < centerx+centerx*0.10)
  1662.             tempx = random(MAX_WIN_X-MIN_WIN_X)+MIN_WIN_X;
  1663.  
  1664.         while (tempy > centery-centery*0.10 && tempy < centery+centery*0.10)
  1665.             tempy = random(MAX_WIN_Y-MIN_WIN_Y)+MIN_WIN_Y;
  1666.  
  1667.         NewRock(tempx,tempy,large);
  1668.     }
  1669. }
  1670.  
  1671. void bar(int x1, int y1, int x2, int y2)
  1672. {
  1673.     int i,j;
  1674.     for (j = y1; j < y2; j++)
  1675.         for (i = x1; i < x2; i++)
  1676.         {
  1677. //            outportb(0x3CD,(j>>6));
  1678.             SetWriteBank(j>>6);
  1679.             putpixel(i,j,cur_color);
  1680.         }
  1681.     return;
  1682. }
  1683.  
  1684. char getpixel(int x, int y)
  1685. {
  1686. //    outportb(0x3CD,((y>>6)<<4));
  1687.     SetReadBank(y>>6);
  1688.     return(*((char far *)0xA0000000+x+(y<<10)));
  1689. }
  1690.  
  1691. void rect(int x1, int y1, int x2, int y2)
  1692. {
  1693.     int i, j;
  1694.     for (j = y1; j < y2; j++)
  1695.     {
  1696.         SetWriteBank(j >> 6);
  1697.         putpixel(x1,j,cur_color);
  1698.         putpixel(x2,j,cur_color);
  1699.     }
  1700.  
  1701.     SetWriteBank(y1>>6);
  1702.     for (i = x1; i < x2; i++)
  1703.         putpixel(i,y1,cur_color);
  1704.     SetWriteBank(y2>>6);
  1705.     for (i = x1; i < x2; i++)
  1706.         putpixel(i,y2,cur_color);
  1707.  
  1708.     return;
  1709. }
  1710.  
  1711. void Init_Graphics(void)
  1712. {
  1713.     int i,j,x,y,col;
  1714.  
  1715.     int ship_offx, ship_offy;
  1716.     int rock_lg_offx, rock_lg_offy;
  1717.     int rock_md_offx, rock_md_offy;
  1718.     int rock_sm_offx, rock_sm_offy;
  1719.     int bul_offx, bul_offy;
  1720.  
  1721.     float angle;
  1722.     char out[10];
  1723.     long corenum;
  1724.  
  1725.     union REGS regs;
  1726.     struct SREGS sregs;
  1727.  
  1728.     cleardevice();
  1729.  
  1730.     loadpics();
  1731.  
  1732.     ship_offx = ship_offy = 0;
  1733.     bul_offx = 0;
  1734.     bul_offy = SHIP_SIZE*4;
  1735.     rock_lg_offx = 0;
  1736.     rock_lg_offy = bul_offy + BUL_SIZE*3;
  1737.     rock_md_offx = SHIP_SIZE*10;
  1738.     rock_md_offy = 0;
  1739.     rock_sm_offx = SHIP_SIZE*10;
  1740.     rock_sm_offy = ROCK_MD_SIZE*5;
  1741.  
  1742.     for (i = 0; i < NUM_SHIP_PICS; i++)
  1743.     {
  1744.         if ((ship_noshld_pic[i] = malloc(SHIP_SIZE*SHIP_SIZE)) == NULL)
  1745.             printf("WARNING: SHIP_NOSHLD[%3] is NULL\n",i);
  1746.         if ((ship_shld_pic[i]   = malloc(SHIP_SIZE*SHIP_SIZE)) == NULL)
  1747.             printf("WARNING: SHIP_SHLD[%3] is NULL\n",i);
  1748.     }
  1749.     for (i = 0; i < NUM_ROCK_PICS; i++)
  1750.     {
  1751.         if ((aster_pic[i] = malloc(ROCK_LG_SIZE*ROCK_LG_SIZE)) == NULL)
  1752.             printf("WARNING: LARGE ROCK[%3] is NULL\n",i);
  1753.         if ((med_aster_pic[i] = malloc(ROCK_MD_SIZE*ROCK_MD_SIZE)) == NULL)
  1754.             printf("WARNING: MED ROCK[%3] is NULL\n",i);
  1755.         if ((small_aster_pic[i] = malloc(ROCK_SM_SIZE*ROCK_SM_SIZE)) == NULL)
  1756.             printf("WARNING: SMALL ROCK[%3] is NULL\n",i);
  1757.     }
  1758.     for (i = 0; i < NUM_BUL_PICS; i++)
  1759.         if ((bullet_pic[i] = malloc(BUL_SIZE*BUL_SIZE)) == NULL)
  1760.             printf("WARNING: BULLET[%3] is NULL\n",i);
  1761.  
  1762.     for (j = 0; j < 4; j++)
  1763.         for (i = 0; i < 10; i++)
  1764.             getimage(ship_noshld_pic[i+j*10],i*SHIP_SIZE,j*SHIP_SIZE,SHIP_SIZE);
  1765.  
  1766.     for (j = 0; j < 4; j++)
  1767.         for (i = 0; i < 10; i++)
  1768.         {
  1769.             for (angle = 0; angle < 6.28318530718; angle += 0.01)
  1770.             {
  1771.                 x = 26*cos(angle) + i*SHIP_SIZE + SHIP_SIZE/2;
  1772.                 y = 26*sin(angle) + j*SHIP_SIZE + SHIP_SIZE/2;
  1773.                 SetWriteBank(y>>6);
  1774.                 putpixel(x,y,2);
  1775.             }
  1776.         }
  1777.  
  1778.     for (j = 0; j < 4; j++)
  1779.         for (i = 0; i < 10; i++)
  1780.             getimage(ship_shld_pic[i+j*10],i*SHIP_SIZE,j*SHIP_SIZE,SHIP_SIZE);
  1781.  
  1782. //    setcolor(4);
  1783.     for (j = 0; j < 3; j++)
  1784.         for (i = 0; i < 10; i++)
  1785.         {
  1786.             if (i+j*10 >= NUM_BUL_PICS)
  1787.                 break;
  1788.             getimage(bullet_pic[i+j*10],i*BUL_SIZE+bul_offx,
  1789.                         j*BUL_SIZE+bul_offy,BUL_SIZE);
  1790. //            bar(i*BUL_SIZE+bul_offx,j*BUL_SIZE+bul_offy,
  1791. //                 i*BUL_SIZE+bul_offx+BUL_SIZE,j*BUL_SIZE+bul_offy+BUL_SIZE);
  1792.         }
  1793.  
  1794.     for (j = 0; j < 5; j++)
  1795.         for (i = 0; i < 10; i+=2)
  1796.         {
  1797.             if ((i/2)+j*5 >= NUM_ROCK_PICS)
  1798.                 break;
  1799.             getimage(aster_pic[(i/2)+j*5],i*ROCK_LG_SIZE+rock_lg_offx,
  1800.                         j*ROCK_LG_SIZE+rock_lg_offy,ROCK_LG_SIZE);
  1801.             getimage(med_aster_pic[NUM_ROCK_PICS-((i/2)+j*5+1)],i*ROCK_MD_SIZE+rock_md_offx,
  1802. //            getimage(med_aster_pic[(i/2)+j*5],i*ROCK_MD_SIZE+rock_md_offx,
  1803.                         j*ROCK_MD_SIZE+rock_md_offy,ROCK_MD_SIZE);
  1804.             getimage(small_aster_pic[(i/2)+j*5],i*ROCK_SM_SIZE+rock_sm_offx,
  1805.                         j*ROCK_SM_SIZE+rock_sm_offy,ROCK_SM_SIZE);
  1806.         }
  1807.  
  1808.  
  1809. //    getch();
  1810. /*
  1811.     i = 0;
  1812.     j = NUM_ROCK_PICS;
  1813.     col = 0;
  1814.     while (!col)
  1815.     {
  1816.         putimage(bullet_pic[i],768,512,BUL_SIZE);
  1817.         printf("ASTEROID %3i  \r",i);
  1818.         out[0] = getch();
  1819.         eraseimage(bullet_pic[i],768,512,BUL_SIZE);
  1820.         if (out[0] == 'q' || out[0] == 'Q')
  1821.             col = 1;
  1822.         if (++i >= NUM_BUL_PICS)
  1823.             i = 0;
  1824.     }
  1825.  
  1826.     getch();
  1827.     exit(0);
  1828. */
  1829. /*
  1830.     for (i = 0; i < MAXROCK; i++)
  1831.         getimage(aster_back[i],512,0,ROCK_LG_SIZE);
  1832.     for (i = 0; i < MAXBUL; i++)
  1833.         getimage(bullet_back[i],512,0,BUL_SIZE);
  1834.     getimage(ship_back,512,0,SHIP_SIZE);
  1835. */
  1836. /*
  1837.     setcolor(52);
  1838.     bar(128,0,192,64);
  1839.  
  1840.     setcolor(44);
  1841.     bar(500,500,516,516);
  1842. */
  1843. //    getimage(aster_pic[0],128,0,ROCK_LG_SIZE);
  1844. //    getimage(med_aster_pic[0],128,0,ROCK_MD_SIZE);
  1845. //    getimage(small_aster_pic[0],128,0,ROCK_SM_SIZE);
  1846. //    getimage(bullet_pic[0],500,500,BUL_SIZE);
  1847.  
  1848. //    getch();
  1849.  
  1850.     cleardevice();
  1851.  
  1852.     for (i = 0; i < NUMSTARS; i++)
  1853.     {
  1854.         star[i].y = random(MAX_WIN_Y-MIN_WIN_Y)+MIN_WIN_Y;
  1855.         star[i].x = random(MAX_WIN_X-MIN_WIN_X)+MIN_WIN_X;
  1856.         star[i].col = random(15);
  1857. //        outport(0x3CD,star[i].y>>6);
  1858.         SetWriteBank(star[i].y>>6)
  1859.         putpixel(star[i].x,star[i].y,star[i].col);
  1860.     }
  1861.  
  1862.     regs.x.ax = 0x1012;
  1863.     regs.x.bx = 0;
  1864.     regs.x.cx = 255;
  1865.     regs.x.dx = FP_OFF( (int far *)&pal[0] );
  1866.     sregs.es  = FP_SEG( (int far *)&pal[0] );
  1867.     int86x(0x10, ®s, ®s, &sregs);
  1868.  
  1869. /*
  1870.     setcolor(31);
  1871.     bar(50,100,250,150);
  1872.  
  1873.     setcolor(14);
  1874.     bar(600,100,700,200);
  1875.     putimage(ship_noshld_pic[0],610,110,SHIP_SIZE);
  1876.  
  1877.     setcolor(14);
  1878.     bar(600,200,700,300);
  1879.     putimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
  1880. //    putimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
  1881.     eraseimage(ship_noshld_pic[0],610,210,SHIP_SIZE);
  1882.  
  1883.     out[0] = 'a';
  1884.     for (i = 0; (i < 250) && (out[0] != 'q'); i+=1)
  1885.     {
  1886.         putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
  1887.         delay(25);
  1888. //        putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
  1889.         eraseimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
  1890.  
  1891.         if (kbhit())
  1892.             out[0] = getch();
  1893.  
  1894. //        putimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
  1895. //        getch();
  1896. //        eraseimage(ship_noshld_pic[i%16],i,i,SHIP_SIZE);
  1897. //        out[0] = getch();
  1898.     }
  1899.  
  1900.     getch();
  1901.     exit(0);
  1902.  
  1903.     cleardevice();
  1904. */
  1905.     return;
  1906. }
  1907.  
  1908. int display_raw(int x, int y, char *filename, int xsize, int ysize)
  1909. {
  1910.     int i, j;
  1911.     int ylim = y + ysize, xlim = x + xsize;
  1912.     unsigned char color;
  1913.     FILE *infile;
  1914.  
  1915. //    ylim = y + SHIP_SIZE*4;
  1916. //    xlim = x + SHIP_SIZE*10;
  1917.  
  1918.     if ((infile = fopen(filename,"rb")) == NULL)
  1919. //    if ((infile = open(filename,O_RDONLY|O_BINARY)) == NULL)
  1920.     {
  1921.         printf("*ERROR* loading: %s\n",filename);
  1922.         return(1);
  1923.     }
  1924.  
  1925.     SetWriteBank(y >> 6);
  1926.     for (j = y; j < ylim; j++)
  1927.     {
  1928.         if ((j & 63) == 0)
  1929.             SetWriteBank(j>>6);
  1930.         for (i = x; i < xlim; i++)
  1931.         {
  1932.             color = getc(infile);
  1933.             if (color == 192)
  1934.                 color = 0;
  1935. //            outport(0x3CD,j >> 6);
  1936. //            SetWriteBank(j>>6);
  1937.             putpixel(i,j,color);
  1938.         }
  1939.     }
  1940.  
  1941.     fclose(infile);
  1942.  
  1943.     return(0);
  1944. }
  1945.  
  1946. void loadpics(void)
  1947. {
  1948.     unsigned int i,j;
  1949.     unsigned char ch;
  1950.  
  1951.     int num;
  1952.  
  1953.     unsigned char black_pal[768];
  1954.  
  1955.     FILE *pal_file;
  1956.  
  1957.     regs.x.ax = 0x38;
  1958.     int86(0x10,®s,®s);
  1959.  
  1960. //    if ((pal_file = fopen("ast_all.pal","rb")) == NULL)
  1961.     if ((pal_file = fopen("fil011.dat","rb")) == NULL)
  1962.     {
  1963.         printf("*ERROR* loading palette!\n");
  1964.         exit(1);
  1965.     }
  1966.  
  1967.     for (i = 0; i < 768; i++)
  1968.         pal[i] = getc(pal_file);
  1969.  
  1970.     fclose(pal_file);
  1971.  
  1972.     for (num = 1; num < 6; num++)
  1973.     {
  1974.         pal[num*3  ] = 63;
  1975.         pal[num*3+1] = num*12;
  1976.         pal[num*3+2] = 0;
  1977.     }
  1978.     for (num = 6; num < 11; num++)
  1979.     {
  1980.         pal[num*3  ] = 63 - (num-5)*12;
  1981.         pal[num*3+1] = 63;
  1982.         pal[num*3+2] = 0;
  1983.     }
  1984.  
  1985.     pal[11*3  ] = 10;
  1986.     pal[11*3+1] = 63;
  1987.     pal[11*3+2] = 10;
  1988.  
  1989.     pal[12*3  ] = 20;
  1990.     pal[12*3+1] = 20;
  1991.     pal[12*3+2] = 20;
  1992.  
  1993.     pal[13*3  ] = 35;
  1994.     pal[13*3+1] = 35;
  1995.     pal[13*3+2] = 35;
  1996.  
  1997.     pal[14*3  ] = 0;
  1998.     pal[14*3+1] = 30;
  1999.     pal[14*3+2] = 0;
  2000.  
  2001.     for (i = 0; i < 768; i++)
  2002.         black_pal[i] = 0;
  2003.  
  2004.     regs.x.ax = 0x1012;
  2005.     regs.x.bx = 0;
  2006.     regs.x.cx = 255;
  2007.  
  2008.     regs.x.dx = FP_OFF( (int far *)&black_pal[0] );
  2009.     sregs.es  = FP_SEG( (int far *)&black_pal[0] );
  2010.  
  2011. //    regs.x.dx = FP_OFF( (int far *)&pal[0] );
  2012. //    sregs.es  = FP_SEG( (int far *)&pal[0] );
  2013.  
  2014.     int86x(0x10, ®s, ®s, &sregs);
  2015.  
  2016. //    display_raw(0,0,"shipall.raw",SHIP_SIZE*10,SHIP_SIZE*4);
  2017.     display_raw(0,0,"fil006.dat",SHIP_SIZE*10,SHIP_SIZE*4);
  2018. //    display_raw(0,SHIP_SIZE*4,"starall.raw",BUL_SIZE*10,BUL_SIZE*3);
  2019.     display_raw(0,SHIP_SIZE*4,"fil007.dat",BUL_SIZE*10,BUL_SIZE*3);
  2020. //    display_raw(0,SHIP_SIZE*4+BUL_SIZE*3,"ast_all.raw",ROCK_LG_SIZE*10,ROCK_LG_SIZE*5);
  2021.     display_raw(0,SHIP_SIZE*4+BUL_SIZE*3,"fil008.dat",ROCK_LG_SIZE*10,ROCK_LG_SIZE*5);
  2022. //    display_raw(SHIP_SIZE*10,0,"ast_all2.raw",ROCK_MD_SIZE*10,ROCK_MD_SIZE*5);
  2023.     display_raw(SHIP_SIZE*10,0,"fil009.dat",ROCK_MD_SIZE*10,ROCK_MD_SIZE*5);
  2024. //    display_raw(SHIP_SIZE*10,ROCK_MD_SIZE*5,"ast_all3.raw",ROCK_SM_SIZE*10,ROCK_SM_SIZE*5);
  2025.     display_raw(SHIP_SIZE*10,ROCK_MD_SIZE*5,"fil010.dat",ROCK_SM_SIZE*10,ROCK_SM_SIZE*5);
  2026.  
  2027. //    for (i = 0; i < 1024; i++)
  2028. //        for (j = 512; j < 516; j++)
  2029. //            putpixel(i,j,i>>2);
  2030.  
  2031. //    getch();
  2032.     fcloseall();
  2033. }
  2034.  
  2035. void getimage(void far *pic_ptr, int x, int y, int size)
  2036. {
  2037.     char loopx, loopx_start = size >> 2;
  2038.     char loopy, loopy_start = size;
  2039. //    char bank = (y>>6)<<4, next_bank = 64 - (y&63);
  2040.     char bank = (y>>6), next_bank = 64 - (y&63);
  2041.     char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
  2042.     int add_to_vid_ptr = 1024 - size;
  2043.  
  2044. //    outportb(0x3CD,bank);
  2045.     SetReadBank(bank);
  2046.  
  2047.     for (loopy = loopy_start; loopy > 0; loopy--)
  2048.     {
  2049.         if (next_bank-- == 0)
  2050.         {
  2051.             bank++;
  2052. //            outportb(0x3CD,bank);
  2053.             SetReadBank(bank);
  2054.             next_bank = 63;
  2055.         }
  2056.         for (loopx = loopx_start; loopx > 0; loopx--)
  2057.             *((long *)((long *)pic_ptr)++) = *((long *)((long *)vid_ptr)++);
  2058.         vid_ptr += add_to_vid_ptr;
  2059.     }
  2060.     return;
  2061. }
  2062.  
  2063. void putimage(void far *pic_ptr, int x, int y, int size)
  2064. {
  2065.     char loopx, loopx_start = size >> 2;
  2066.     char loopy, loopy_start = size;
  2067.     char bank = (y>>6)/*+((y>>2)&0xF0)*/, next_bank = 64 - (y & 63);
  2068.     char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
  2069.     int add_to_vid_ptr = 1024 - size;
  2070.  
  2071. //    outportb(0x3CD,bank);
  2072.     SetWriteBank(bank);
  2073.  
  2074.     for (loopy = loopy_start; loopy > 0; loopy--)
  2075.     {
  2076.         if (next_bank-- == 0)
  2077.         {
  2078. //            bank += 0x11;
  2079. //            bank++;
  2080. //            outportb(0x3CD,++bank);
  2081.             SetWriteBank(++bank);
  2082.             next_bank = 63;
  2083.         }
  2084.         for (loopx = loopx_start; loopx > 0; loopx--)
  2085.         {
  2086.             if (*((long *)((long *)pic_ptr)) != 0)
  2087.                 *((long *)((long *)vid_ptr)++) = *((long *)((long *)pic_ptr)++);
  2088.             else
  2089.             {
  2090.                 (long *)((long *)vid_ptr)++;
  2091.                 (long *)((long *)pic_ptr)++;
  2092.             }
  2093.         }
  2094.         vid_ptr += add_to_vid_ptr;
  2095.     }
  2096. }
  2097.  
  2098. void eraseimage(void far *pic_ptr, int x, int y, int size)
  2099. {
  2100.     char loopx, loopx_start = size >> 2;
  2101.     char loopy, loopy_start = size;
  2102.     char bank = y >> 6, next_bank = 64 - (y & 63);
  2103.     char far *vid_ptr = (char far *) 0xA0000000 + x + (y << 10);
  2104.     int add_to_vid_ptr = 1024 - size;
  2105.  
  2106. //    outportb(0x3CD,bank);
  2107.     SetWriteBank(bank);
  2108.  
  2109.     for (loopy = loopy_start; loopy > 0; loopy--)
  2110.     {
  2111.         if (next_bank-- == 0)
  2112.         {
  2113. //            outportb(0x3CD,++bank);
  2114.             SetWriteBank(++bank);
  2115.             next_bank = 63;
  2116.         }
  2117.         for (loopx = loopx_start; loopx > 0; loopx--)
  2118.         {
  2119.             if (*((long *)((long *)pic_ptr)) != 0)
  2120.             {
  2121.                 *((long *)((long *)vid_ptr)++) = 0;
  2122.                 (long *)((long *)pic_ptr)++;
  2123.             }
  2124.             else
  2125.             {
  2126.                 (long *)((long *)vid_ptr)++;
  2127.                 (long *)((long *)pic_ptr)++;
  2128.             }
  2129.         }
  2130.         vid_ptr += add_to_vid_ptr;
  2131.     }
  2132. }
  2133.  
  2134. void putpixel2(int x, int y, long color)
  2135. {
  2136.     static long far *ptr = (long far *) 0xA0000000;  /* START VID MEM */
  2137.  
  2138. //    outportb(0x3CD,y>>6);
  2139.     SetWriteBank(y>>6);
  2140.  
  2141.     *((long *)((long *)ptr+(long)x+(long)(y<<10))) = (long)color;    /* Write directly to mem         */
  2142.  
  2143.     return;
  2144. }
  2145.  
  2146. long getpixel2(int x, int y)
  2147. {
  2148.     long temp;
  2149. //    long far *ptr = (long far *) 0xA0000000;  /* START VID MEM */
  2150.  
  2151. //    outportb(0x3CD,((y>>6)<<4));
  2152.     SetReadBank(y>>6);
  2153.  
  2154.     temp = *((long far *)((long far *)(0xA0000000)+(long)(x>>2)+(long)(y<<8)));
  2155.  
  2156.     return(temp);
  2157. }
  2158.  
  2159. int initVesa(void)
  2160. {
  2161.     long testmode;
  2162.     struct VESAINFO
  2163.     {
  2164.         unsigned char tag[4];
  2165.         unsigned int version;
  2166.         char far *oem_ptr;
  2167.         unsigned long capabilities;
  2168.         int far *modes_ptr;
  2169.         unsigned int mem64blocks;
  2170.  
  2171.         char wasted[242];
  2172.     } info;
  2173.  
  2174.     struct MODEINFO
  2175.     {
  2176.         unsigned int attrib;
  2177.         unsigned char wina, winb;
  2178.         unsigned int grain, size, winaseg, winbseg;
  2179.         void far *bankfunc;
  2180.         unsigned int bytes_per_row,xres,yres;
  2181.         unsigned char xchar, ychar, bitplanes, bppixel, numbanks, memmodel,
  2182.                           banksize, pages, reserved, redmask, redpos, greenmask,
  2183.                           greenpos, bluemask, bluepos, rsvdmask, rsvdpos, dcinfo;
  2184.         char wasted[216];
  2185.     } mode;
  2186.  
  2187.     regs.h.ah = 0x4F;
  2188.     regs.h.al = 0x00;
  2189.     regs.x.di = FP_OFF( (int far *)&info );
  2190.     sregs.es  = FP_SEG( (int far *)&info );
  2191.     int86x(0x10, ®s, ®s, &sregs);
  2192.  
  2193.     if (info.tag[0] != 'V' || info.tag[1] != 'E' ||
  2194.          info.tag[2] != 'S' || info.tag[3] != 'A')
  2195.          return(1);
  2196.  
  2197.     testmode = 1;
  2198.     while (*info.modes_ptr != -1 && testmode != 0x105)
  2199.         testmode = *info.modes_ptr++;
  2200.  
  2201.     if (testmode == 1)
  2202.         return(1);
  2203.  
  2204.     if (info.mem64blocks < 16)
  2205.         return(1);
  2206.  
  2207.     regs.x.ax = 0x4F01;
  2208.     regs.x.cx = 0x105;
  2209.     regs.x.di = FP_OFF( (int far *)&mode );
  2210.     sregs.es  = FP_SEG( (int far *)&mode );
  2211.     int86x(0x10,®s,®s,&sregs);
  2212.  
  2213.     if (mode.attrib & 1 != 1)
  2214.         return(1);
  2215.  
  2216.     if ( (mode.wina&2) >> 1 == 1)
  2217.         ReadWin = 0;
  2218.     else if ( (mode.winb&2) >> 1 == 1)
  2219.         ReadWin = 1;
  2220.     else
  2221.         return(1);
  2222.  
  2223.     if ( (mode.wina&4) >> 2 == 1)
  2224.         WriteWin = 0;
  2225.     else if ( (mode.winb&4) >> 2 == 1)
  2226.         WriteWin = 1;
  2227.     else
  2228.         return(1);
  2229.  
  2230.     if (mode.grain != 64)
  2231.         return(1);
  2232.  
  2233.     regs.x.ax = 0x4F02;
  2234.     regs.x.bx = 0x0105;
  2235.     int86(0x10,®s,®s);
  2236.  
  2237.     return(0);
  2238. }
  2239.  
  2240. void cleardevice(void)
  2241. {
  2242.     static int ati_mode_test;
  2243.     static int first_time = 0;
  2244.  
  2245.     if (first_time == 0)
  2246.     {
  2247.         if (graphics_chip == ATI)
  2248.         {
  2249.             printf("\nHi there!  I see you have selected the ATI graphics chip.");
  2250.             printf("\nThat's wonderfull, but unfortunately, I have no clue what");
  2251.             printf("\nmode to set it to.  Actually, I _do_ have a clue, but");
  2252.             printf("\nI have two conflicting sources.  So, please select either");
  2253.             printf("\nmode 0x64 (hex, 100 decimal) or mode 0x65 (101 decimal).");
  2254.             printf("\nActually, try 101 first. :)");
  2255.             printf("\nThanks. :)");
  2256.             printf("\nBTW - I wouldn't suggest trying *anything* other than these two. :)");
  2257.             printf("\n\nWell?  What'll it be?  100? or 101?  -> ");
  2258.             scanf("%d",&ati_mode_test);
  2259.         }
  2260.         else if (graphics_chip == VESA)
  2261.         {
  2262.             if (initVesa() == 1)
  2263.             {
  2264.                 printf("ERROR initializing VESA graphics. Exiting...\n");
  2265.                 exit(1);
  2266.             }
  2267.         }
  2268.     }
  2269.  
  2270.     if (first_time == 0)
  2271.         printf("\nSetting graphics mode...");
  2272.  
  2273.     if (graphics_chip == TSENG)
  2274.         regs.x.ax = 0x38;
  2275.     else if (graphics_chip == TRIDENT)
  2276.         regs.x.ax = 0x62;
  2277.     else if (graphics_chip == ATI)
  2278. //        regs.x.ax = 0x65;
  2279.         regs.x.ax = ati_mode_test;
  2280.     else if (graphics_chip == VESA)
  2281.     {
  2282.         regs.x.ax = 0x4F02;
  2283.         regs.x.bx = 0x0105;
  2284.     }
  2285.     int86(0x10,®s,®s);
  2286.  
  2287. //    if (first_time == 0)
  2288. //        printf("\nGraphics mode set:  Setting SVGA card-specific registers.");
  2289.  
  2290.     if (graphics_chip == TRIDENT)
  2291.     {
  2292.         outportb(0x3C4,0x0B);
  2293.         outportb(0x3C5,0x00);
  2294.         inportb(0x3C5);
  2295.     }
  2296.     else if (graphics_chip == ATI)
  2297.     {
  2298.         ati_index = *((int far *)0xC0000010);
  2299.         outportb(ati_index,0xBE);
  2300.         outportb(ati_index,(inportb(ati_index)) | 0x8 );
  2301.     }
  2302.  
  2303. //    if (first_time == 0)
  2304. //        printf("\nIf this is still in text mode, than you are hosed.");
  2305.  
  2306.     first_time = 1;
  2307.     return;
  2308. }
  2309.  
  2310. void Init_Sound(void)
  2311. {
  2312.     int i;
  2313.     if (sound_mode == on)
  2314.     {
  2315.         i = 0;
  2316.         drawscreen();
  2317. //        soundb[i++] = loadsound("explode.voc");
  2318.         soundb[i++] = loadsound("fil001.dat");
  2319.         drawscreen();
  2320. //        soundb[i++] = loadsound("blasto.voc");
  2321.         soundb[i++] = loadsound("fil002.dat");
  2322.         drawscreen();
  2323. //        soundb[i++] = loadsound("exp1.voc");
  2324.         soundb[i++] = loadsound("fil003.dat");
  2325.         drawscreen();
  2326. //        soundb[i++] = loadsound("gm-ovr2.voc");
  2327.         soundb[i++] = loadsound("fil004.dat");
  2328.         drawscreen();
  2329. //        soundb[i++] = loadsound("enough.voc");
  2330.         soundb[i++] = loadsound("fil005.dat");
  2331.         drawscreen();
  2332.  
  2333.         SB_Setup();
  2334.         SB_SetVect(sample);
  2335.     }
  2336.     return;
  2337. }
  2338.  
  2339. void De_Init_Graphics(void)
  2340. {
  2341.     int i;
  2342.  
  2343.     for (i = 0; i < NUM_SHIP_PICS; i++)
  2344.     {
  2345.         free(ship_noshld_pic[i]);
  2346.         free(ship_shld_pic[i]);
  2347.     }
  2348.     for (i = 0; i < NUM_ROCK_PICS; i++)
  2349.     {
  2350.         free(aster_pic[i]);
  2351.         free(med_aster_pic[i]);
  2352.         free(small_aster_pic[i]);
  2353.     }
  2354.     for (i = 0; i < NUM_BUL_PICS; i++)
  2355.         free(bullet_pic[i]);
  2356.  
  2357.     if (graphics_chip == VESA)
  2358.     {
  2359.         regs.x.ax = 0x4F02;
  2360.         regs.x.bx = 0x0003;
  2361.     }
  2362.     else
  2363.         regs.x.ax = 0x0003;
  2364.  
  2365.     int86(0x10,®s,®s);
  2366.     return;
  2367. }
  2368.  
  2369. void De_Init_Sound(void)
  2370. {
  2371.     int i;
  2372.  
  2373.     if (sound_mode == on)
  2374.     {
  2375.         if (player.status == dieing)
  2376.             while (voc_mode);
  2377.         VocStop();
  2378.         VocPlay((char far *)soundb[QUIT]);
  2379.         while (voc_mode);
  2380.     }
  2381.  
  2382.     if (sound_mode == on)
  2383.     {
  2384.         VocStop();
  2385.  
  2386.         for (i = 0; i < MAXSND; i++)
  2387.             free((char huge *)soundb[i]);
  2388.  
  2389.         VocStop();
  2390.  
  2391.         SB_RemoveVect();
  2392.     }
  2393.     return;
  2394. }
  2395.  
  2396. void Setup_Key_Interrupt(void)
  2397. {
  2398.     return;
  2399. }
  2400.  
  2401. void Enable_Key_Interrupt(void)
  2402. {
  2403.     int9->p = addr->p;
  2404.     addr->p = (char far *) lookkey;
  2405. }
  2406.  
  2407. void Disable_Key_Interrupt(void)
  2408. {
  2409. /* Important! This next statement returns keyboard control to the BIOS
  2410.     services.  You must execute this command to use any of the Turbo C
  2411.     input routines!   OR ELSE THE COMPUTER WILL LOCK UP!!! */
  2412.     addr->p = int9->p;
  2413. }
  2414.  
  2415. void interrupt lookkey(void)
  2416. {
  2417. //    char keyb = inportb(96);
  2418. //    char far *t = (char far *) 1050;
  2419.  
  2420.     switch (inportb(96))                                // Read from keyboard
  2421.     {
  2422.         case 1   :
  2423.             k.esc = PRESSED; break;
  2424.  
  2425. //        case keyOpt.left_press :
  2426.         case 75    :
  2427.             k.left = PRESSED; break;
  2428.  
  2429. //        case keyOpt.left_unpress :
  2430.         case 203    :
  2431.             k.left = UNPRESSED; break;
  2432.  
  2433. //        case keyOpt.right_press :
  2434.         case 77    :
  2435.             k.right = PRESSED; break;
  2436.  
  2437. //        case keyOpt.right_unpress :
  2438.         case 205    :
  2439.             k.right = UNPRESSED; break;
  2440.  
  2441. //        case keyOpt.thrust_press :
  2442.         case 72    :
  2443.             k.thrust = PRESSED; break;
  2444.  
  2445. //        case keyOpt.thrust_unpress :
  2446.         case 200    :
  2447.             k.thrust = UNPRESSED; break;
  2448.  
  2449. //        case keyOpt.fire_press :
  2450.         case 29    :
  2451.             k.fire = PRESSED; break;
  2452.  
  2453. //        case keyOpt.fire_unpress :
  2454.         case 157    :
  2455.             k.fire = UNPRESSED; break;
  2456.  
  2457. //        case keyOpt.shield_press :
  2458.         case 42    :
  2459.             k.shield = PRESSED;
  2460.             break;
  2461.  
  2462. //        case keyOpt.shield_unpress :
  2463.         case 170    :
  2464.             k.shield = UNPRESSED; break;
  2465.  
  2466.  
  2467. // F4 pauses for now.
  2468.         case 62  :
  2469. //            exit(0); break;
  2470.             k.pause = PRESSED; break;
  2471.         case 190 :
  2472. //            exit(0); break;
  2473.             k.pause = UNPRESSED; break;
  2474.  
  2475. /* For some reason, once bios discovers the 5 key on the key pad is press
  2476. and numlock is not on, the system locks up.  So I put another key code
  2477. (57 = space) into the place where the 5 key code (76) is.  */
  2478. /*
  2479.         case 76  :
  2480.             k.mid = PRESSED;
  2481.             outport(96,57);
  2482.             break;
  2483.         case 204 :
  2484.             k.mid = UNPRESSED;
  2485.             break;
  2486. */
  2487.     }
  2488.  
  2489.     outportb(0x20,0x20);
  2490.  
  2491.     return;
  2492. }
  2493.  
  2494. char huge *loadsound(char *filename)
  2495. {
  2496.     int file;
  2497.     WORD ret,rate;
  2498.     struct stat mystat;
  2499.     long length;
  2500.     char huge *base,huge *base2;
  2501.  
  2502.     stat(filename,&mystat);
  2503.     length=mystat.st_size;
  2504. //    base=farmalloc(length);
  2505.     base=malloc(length);
  2506.     if(!base)
  2507.     {
  2508.         printf("Not enough memory for: %s\n",filename);
  2509.         return(NULL);
  2510.     }
  2511.     file=open(filename,O_RDONLY|O_BINARY);
  2512.     if(file== -1)
  2513.     {
  2514.         printf("Cannot open file: %s\n",filename);
  2515.         if(base)
  2516. //            farfree(base);
  2517.             free(base);
  2518.         return(NULL);
  2519.     }
  2520.     base2=base;
  2521.     do
  2522.     {
  2523.         // do not use this call in small model!
  2524.         ret=read(file,base2,32700);
  2525.         base2+=ret;
  2526.     } while(ret==32700);
  2527.     close(file);
  2528.     return(base);
  2529. }